import { createStore, useStore as useStoreVuex, Store } from 'vuex'
import { IRootState, IStoreType } from './type'
import { loginModule as login } from './login'
import { tagModule as tag } from './tag'

const store = createStore<IRootState>({
  state: () => {
    return {
      name: 'chanchaw',
      age: 11
    }
  },
  mutations: {
    // changeKeepAlive(state,param: string) {
    //   const item = state.keepAlive.find(x => x === param)
    //   if(!item) state.keepAlive.push(param)
    // }
  },
  modules: {
    login,
    tag
  }
})

export function useStore(): Store<IStoreType> {
  return useStoreVuex()
}

export function setupStore() {
  store.dispatch('login/loadLocalAction')
  store.dispatch('tag/loadLocalAction')
  store.dispatch('login/printUserMenuAction')
}

export default store
